package com.webapp.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.webapp.model.Comment;
import com.webapp.model.CommentModel;

/**
 * Servlet implementation class EditComment
 */
public class EditComment extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EditComment() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int commentid = Integer.parseInt((String)request.getParameter("COMMENTID"));
		int userid = Integer.parseInt((String)request.getParameter("USERID"));
		int postid = Integer.parseInt((String)request.getParameter("POSTID"));
		String text = request.getParameter("COMMENTTXT");
		Comment comment = new Comment(postid, text, userid, commentid);
		CommentModel cm = new CommentModel();
		if (cm.modifyComment(comment)) {
			response.sendRedirect("Posts.jsp");
		} else {
			response.sendRedirect("Error.jsp");
		}
	}

}
